import { createRouter, createWebHashHistory } from 'vue-router'
const Layout = () => import("@/views/Layout.vue")
const Home = () => import("@/views/homePage")
const Login = () => import('@/views/login/index')
import TopCategory from '@/views/categoryPage'
import SubCategory from '@/views/categoryPage/sub.vue'
const Goods = () => import('@/views/goods/index')
const Cart= ()=>import ('@/views/cart')
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      { path: '/', component: Home },
      // 分类
      {
        path: '/category/:id',
        name: 'category',
        component: TopCategory
      },
      // 二级分类
      {
        path: '/category/sub/:id',
        name: 'category_sub',
        component: SubCategory
      },
      // 商品详情
      {
        path: '/product/:id',
        name: 'product',
        component: Goods
      }
    ]
  },
  { path: '/login', component: Login },
  { path: '/cart', component: Cart },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return { top: 0 }
  },
})

export default router
